/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package creater;

import java.io.*;
import database.*;

/**
 *
 * @author user
 */
public class newsCreater {

/*
    public static void main(String args[]) {
    try {
    newsCreater j = new newsCreater();
    //j.insert("aaa", "bbbbb","web\\news\\newsbydate\\model2.html");
    j.newsSizeByFolder("web\\news\\newsbydate\\200905");
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
*/
    public newsCreater() {
    }

    public static void insert(String inTitle, String inContent, String inAddress,String inRoot) throws Exception {
        File model = new File(inRoot+"news\\newsbydate\\model\\model.html");
        File outFile = File.createTempFile("name", ".tmp");

        FileInputStream fis = new FileInputStream(model);
        BufferedReader in = new BufferedReader(new InputStreamReader(fis));

        FileOutputStream fos = new FileOutputStream(outFile);
        PrintWriter out = new PrintWriter(fos);

        String thisLine;
        int i = 1;
        while ((thisLine = in.readLine()) != null) {
            if (i == 6) {//6 for title
                out.println("<title>" + inTitle + "</title>");
            }
            if (i == 219) {//6 for title
                out.println("<p>" + inContent + "</p>");
            }
            out.println(thisLine);
            i++;
        }
        out.flush();
        out.close();
        in.close();

        //model.delete();
        System.out.println(inAddress);
        File saveAs = new File(inAddress);
        saveAs.delete();
        outFile.renameTo(saveAs);
    }

    public static int newsSizeByFolder(String inAddress) throws IOException {

        //System.out.println(inAddress);
        File file = new File(inAddress);
        //System.out.println("sdsd"+file.getCanonicalPath());
        //System.out.println(file.list().length);
        //System.out.println("sdsd"+file.getCanonicalPath());
        int size = file.list().length;
        return size;

    }
}
